<template>
  <el-table
    ref="commonTable"
    :data="tableData"
    @row-click="rowClick"
    @selection-change="changeSelect"
    v-loading="loading"
    highlight-current-row
    style="width: 100%; margin-right: 10px"
  >
    <el-table-column type="selection" width="55"></el-table-column>
    <template v-if="tableid == '30'">
      <el-table-column label="身份证号" prop="jmsfzh"> </el-table-column>
      <el-table-column label="姓名" prop="xm"> </el-table-column>
      <el-table-column label="个人编号" prop="zgbh"> </el-table-column>
    </template>
    <template v-else>
      <el-table-column label="身份证号" prop="aac002"> </el-table-column>
      <el-table-column label="姓名" prop="aac003"> </el-table-column>
      <el-table-column v-if="tableid == '41'" label="个人编号" prop="aac001">
      </el-table-column>
      <el-table-column v-else label="家属编号" prop="pcc001"> </el-table-column>
    </template>
  </el-table>
</template>
<script>

module.exports = {
  name: "personListCommon",
  props: ["tableid"],
  data() {
    return {
      tableData: [],
      chooseArr: [],
      selectStr: "",
      loading: false,
    };
  },
  methods: {
    // 点击表格行
    rowClick(row) {
      this.$parent.changeWorker(row);
    },
    // 设置第一行为高亮
    highlight(row) {
      this.$refs.commonTable.setCurrentRow(row);
    },
    // 选中所有
    selectAll(){
      this.$refs.commonTable.toggleAllSelection();
    },
    // 监听多选框
    changeSelect(selection) {
      this.chooseArr = selection;
      if (selection.length == 0) {
        this.selectStr = "";
      } else {
        for (let i = 0; i < selection.length; i++) {
          if (i == 0) {
            this.selectStr = selection[i].id;
          } else {
            this.selectStr = this.selectStr + "," + selection[i].id;
          }
        }
      }
    },
    // 查询数据
    async getPersonList() {
      const params = {
        tableId: this.tableid,
      };
      const res = await api.queryBody(
        "/admin/api/bfmc/BasicInformationModificationController/rightDataList",
        params
      );
      if (res.code == 1) {
        this.tableData = res.data;
      } else {
        this.$message.error(res.msg);
      }
    },
    // 删除数据
    deleteRows() {
      if (this.chooseArr.length == 0) {
        this.$message.error("请先选中一条数据");
      } else {
        this.$confirm("此操作将删除该行, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(async () => {
            let url =
              "/admin/api/bfmc/BasicInformationModificationController/dataDelete";
            let res = await api.queryBody(url, {
              ids: this.selectStr,
              tableId: this.tableid,
            });
            if (res.code == 1) {
              this.$message.success("删除成功");
              this.loading = true;
              if (res.data.length == 0) {
                this.$parent.hasData = false;
              }
              // 更新右侧数据
              this.tableData = res.data;
              setTimeout(() => {
                this.loading = false;
              }, 500);
            } else {
              this.$message.error(res.msg);
            }
          })
          .catch(() => {
            this.$message.info("已取消删除");
          });
      }
    },
    // 提交数据
    async submitRow(bh){
      if (this.chooseArr.length == 0) {
        this.$message.error("请先选中一条数据");
      } else {
        const params = {
          dataid: this.selectStr,
          lcbh: bh,
        };
        const res = await api.queryBody(
          "/admin/api/pmc/ProcessManagementController/review",
          params
        );
        if (res.code == 1) {
          this.$message.success(res.msg);
          setTimeout(() => {
            this.$parent.getData();
          }, 500);
        } else {
          this.$message.error(res.msg);
        }
      }
    }
  },
};
</script>